home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 36 / dvmon13.zip / DVMON.C next >
C/C++ Source or Header  |  1988-06-20  |  6KB  |  206 lines

  1. /* DVMON.C    Turbo C 1.5 Source for DESQview 2.0 Performance Monitor */
  2. /*
  3.  *    Copyright 1988 Barry A. Burke. All rights, except those
  4.  *    specifically granted herein are reserved by the author. The right
  5.  *    to copy and distribute this material is granted without fee for
  6.  *    any and all non-commercial use. This material specifically may
  7.  *    not be distributed or sold for a fee nor incorporated in whole or
  8.  *    in part into any other product that is distributed or sold for a
  9.  *    fee without specific permission of the author. To obtain special
  10.  *    permission or to report any difficulties with this material
  11.  *    contact:
  12.  *                      Barry A. Burke
  13.  *                      Marketing Insights
  14.  *                      35 Elizabeth Circle
  15.  *                      Framingham, MA  01701
  16.  *
  17.  *    THIS MATERIAL IS DISTRIBUTED "as is" WITHOUT ANY EXPRESSED OR
  18.  *    IMPLIED WARRANTY OR LIABILITY FOR DIRECT, INDIRECT OR
  19.  *    CONSEQUENTIAL DAMAGES.
  20.  *
  21.  *
  22.  * Revision History:
  23.  * 1.0    May 13, 1988    BAB    Initial version sent to Quarterdeck BBoard
  24.  * 1.1  May 16, 1988    BAB     Removed DV Criticial stuff - fixes Bell
  25.  *                problem (better, anyway).
  26.  * 1.2  June 17, 1988   RDB     reduced CPU overhead by factor of 5, memory use
  27.  *                              by factor of 3
  28.  * 1.3  June 20, 1988   RDB     some more performance tweaks
  29.  */
  30. #pragma inline
  31.  
  32. #include <time.h>
  33. #include <bios.h>
  34. #include <dos.h>
  35. #include <stdlib.h> 
  36.  
  37. /* TurboC System Stuff */
  38. unsigned       _stklen = 128;          /* need smallest stack */
  39. unsigned       _heaplen = 1;           /* smallest heap possbile */
  40.  
  41. void _setenvp(void){}                  /* dummy out _setenvp */
  42. void _setargv(void){}                  /* dummy out _setargv */
  43.  
  44. void exit(int c)                       /* minimal EXIT() function */
  45. { _exit(c);}
  46.  
  47. /* Global Variables */
  48.  
  49. int    IN_DV = 0;
  50.  
  51. #define INCRSECS        1              /* Number of seconds between */
  52.                                        /* Updates                   */
  53. #define DvPause() _AX = 0x1000, geninterrupt(0x15)
  54. #define LongTicks() biostime(0,0L)
  55.  
  56. #define bioschar(c) _AL = c ; _AH = 0x0E ; _BX = 0x0007 ; asm push bp ; asm int  10h ; asm pop  bp
  57. #define biosgoto(row,col) _DH = row ; _DL = col ; _AH= 0x02 ; _BH = 0 ; __int__(0x10)
  58.  
  59. /* Function Declarations */
  60.  
  61. static int near DvGetVersion(void)
  62. {
  63.         asm     mov     CX,'DE'        /* Invalid date */
  64.         asm     mov     DX,'SQ'        /* accepted by DESQview */
  65.         asm     mov     AX,2B01H       /* DOS Set Date/DESQ int */
  66.     asm    int    21H
  67.  
  68.     asm    cmp    AL,0FFH
  69.     asm    je    NO_DV
  70.  
  71.         asm     mov     BX,AX          /* returned version number */
  72.     asm    mov    IN_DV,1
  73.     asm    jmp    short DVGV_RET
  74.  
  75. NO_DV:
  76.     asm    sub    AX,AX
  77.  
  78. DVGV_RET:
  79. }
  80.  
  81. void pascal put_int( int val, int len )
  82. {
  83.    char number[8] ;
  84.    register int count = 0 ;
  85.    char pad = (len > 0) ? '0' : ' ' ;
  86.  
  87.    do {
  88.       number[count++] = (val % 10) + '0' ;
  89.       val /= 10 ;
  90.       } while (val) ;
  91.    if (len < 0)
  92.       len = -len ;
  93.    while (count < len)
  94.       number[count++] = pad ;
  95.    while (--count >= 0)
  96.       {
  97.       _AL = number[count] ;
  98.       _AH = 0x0E ;
  99.       _BX = 0x0007 ;
  100.       asm push bp
  101.       asm int  10h
  102.       asm pop  bp
  103.       }
  104. }
  105.  
  106. void pascal bioswrite( register char *s )
  107. {
  108.    while (*s)
  109.       {
  110.       _AL = *s++ ;
  111.       _AH = 0x0E ;
  112.       _BX = 0x0007 ;
  113.       asm push bp
  114.       asm int  10h
  115.       asm pop  bp
  116.       }
  117. }
  118.  
  119. void main()
  120. {
  121.    long goaltime ;
  122.    register int counter, maxcount;
  123.    struct time tim ;
  124.    struct date dat ;
  125.  
  126.    DvGetVersion();                         /* Find out if we're in DV */
  127.    if ( !IN_DV )
  128.       {
  129.       bioswrite( "This is a DESQview program!" ) ;
  130.       exit(1);
  131.       }
  132.  
  133.    bioswrite( "DVMON 1.3:\r\n Calibrating..." );/* Start calibration loop */
  134.  
  135.    maxcount = 0;
  136.    goaltime = LongTicks() + 2 ;          /* since we're the only one running, */
  137.                                          /* we don't need to wait very long to */
  138.    while ( LongTicks() < goaltime )      /* get to an even-tick boundary */
  139.       ;
  140.    goaltime = LongTicks() + 18;
  141.    while ( LongTicks() < goaltime )
  142.       {
  143.       DvPause();
  144.       ++maxcount;
  145.       }
  146.  
  147.    maxcount = ( maxcount * INCRSECS );
  148.  
  149.    _AH = 0x01 ;      /* make cursor invisible */
  150.    _CH = 15 ;
  151.    _CL = 15 ;
  152.    __int__(0x10) ;
  153.  
  154.    biosgoto(0,0) ;
  155.    getdate(&dat) ;
  156.    put_int( dat.da_mon, -2 ) ;
  157.    bioschar( '-' ) ;
  158.    put_int( dat.da_day, 2 ) ;
  159.    bioschar( '-' ) ;
  160.    put_int( dat.da_year - 1900, 2 ) ;
  161.    bioswrite("        \r\n"  /* cover anything which might already be on the screen */
  162.              "   % CPU unused" ) ;
  163.    while ( 1 )
  164.       {
  165.       counter = 0;
  166.       goaltime = LongTicks() + (INCRSECS*18L);
  167.       if ( goaltime > 1572000L )      /* Handle midnight wrap */
  168.          goaltime = 1572000L;
  169.       while ( LongTicks() < goaltime )
  170.          {
  171.          DvPause();
  172.          ++counter;
  173.          }
  174.  
  175.       gettime(&tim);
  176.       if (tim.ti_hour == 0 && tim.ti_min == 0)
  177.          {    /* at midnight, we need to update the date */
  178.          biosgoto(0,0) ;
  179.          getdate(&dat) ;
  180.          put_int( dat.da_mon, -2 ) ;
  181.          bioschar( '-' ) ;
  182.          put_int( dat.da_day, 2 ) ;
  183.          bioschar( '-' ) ;
  184.          put_int( dat.da_year - 1900, 2 ) ;
  185.          }
  186.       biosgoto(0,9) ;
  187.       put_int( tim.ti_hour, -2 ) ;
  188.       bioschar( ':' ) ;
  189.       put_int( tim.ti_min, 2 ) ;
  190.       bioschar( ':' ) ;
  191.       put_int( tim.ti_sec, 2 ) ;
  192.       biosgoto(1,0) ;
  193.       put_int( (int)(counter * 100L / maxcount), -3 ) ;
  194.  
  195. /* In order to avoid the appearance we are locked up if somebody tries to
  196.  * type in our window, then switch away, we flush the bios keyboard buffer
  197.  * once a second. This also prevent DESQview's warning bell from running
  198.  * until the next key pressed, tho I don't really know why.
  199.  */
  200.  
  201.       while ( bioskey( 1 ) )  /* Flush keyboard buffer */
  202.          bioskey( 0 );
  203.       }
  204. }
  205.  
  206.